<template>
  <MyHeader> </MyHeader>
  <el-row>
    <el-col :span="3">
    </el-col>
    <el-col :span="18" style="margin-top: 50px ">
        <h3>添加标签</h3>
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="tag英文">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="tag中文">
          <el-input v-model="form.cnName"></el-input>
        </el-form-item>
        <el-form-item label="tag类型">
          <el-input v-model="form.clazz"></el-input>
          <!--              <el-select v-model="form.region" placeholder="请选择活动区域">-->
          <!--                <el-option label="区域一" value="shanghai"></el-option>-->
          <!--                <el-option label="区域二" value="beijing"></el-option>-->
          <!--              </el-select>-->
        </el-form-item>

        <el-form-item label="额外信息">
          <el-input type="textarea" v-model="form.massage"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button @click="onSubmit">立即提交</el-button>
          <el-button @click="onEX">取消</el-button>
        </el-form-item>
      </el-form>
    </el-col>
    <el-col :span="3">
    </el-col>
  </el-row>
</template>

<script>
import MyHeader from "@/components/MyHeader"
import {inject} from 'vue'
import axios from 'axios'
import $cookies from "vue-cookie";
export default {
  name: "AddTag",
  data(){
    return{
      myBaseURL: inject('$baseURL'),
      refresh_carder:1,
      isLogin: false,
      form: {
        name: '',
        cnName: '',
        clazz: '',
        massage: '',
      }
    }
  },
  components:{
    MyHeader
  },
  methods:{
    onSubmit: function (){
      if(this.isLogin !== "true")
      {
          this.$message.error('请先登录！');//alert("请先登录！")
        return;
      }

      if(this.form.name === "" || this.form.cnName === "" || this.form.clazz === "")
      {
          this.$message.error('数据不全！');//alert("数据不全！")
        return
      }
      const token = $cookies.get("token")
      axios({
        method:'post',
        url:'/tag/add',
        baseURL:this.myBaseURL,
        params:{
          name: this.form.name,
          cnName: this.form.cnName,
          clazz: this.form.clazz,
          message: this.form.massage
        },
        headers: {
          "Content-Type": "multipart/form-data",
          "User-Token": token,
        }
      }).then(response => {
        if(response.data === 1)
            this.$message.success('提交成功！');//alert("提交成功！")
        else
            this.$message.error('提交失败！');//alert("提交失败！")
      })
    },
    onEX:function(){
      this.form.name = ""
      this.form.cnName = ""
      this.form.clazz = ""
      this.form.massage = ""
    }
  },
  mounted() {
    //this.getLoginState()
    const islogin = $cookies.get("isLogin")
    console.log(islogin)
    this.isLogin = islogin
  }
}
</script>

<style scoped>

</style>
